﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using Ice.Toolkit.Data.Entity;

namespace Ice.Toolkit.Data.Sql
{
    internal class SqlOrderBy<T, TKey> where T : EntityBase<T>, new()
    {
        public String SqlOrderByText { get; private set; }

        public Expression<Func<T, TKey>> SqlExpression { get; private set; }

        public OrderByType ThenOrderBy { get; private set; }

        public SqlOrderBy(Expression<Func<T, TKey>> expression, OrderByType orderByType)
        {
            SqlExpression = expression;
            ThenOrderBy = orderByType;
            Compile();
        }

        public void Compile()
        {
            var body = SqlExpression.Body as MemberExpression;

            SqlOrderByText = body.Member.Name + " " + ThenOrderBy.ToString();
        }
    }
}
